package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.Util;
import asteroids.model.CollisionObject;
import asteroids.model.Ship;

public class LessThan extends ComparisonExpression {
	public LessThan(E e1, E e2) {
		super(e1, e2);
	}


	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){	
		try{
			if(getExpression1().getContent(map, givenCollisionObject)instanceof Double && getExpression2().getContent(map, givenCollisionObject) instanceof Double){
				if(!(Util.fuzzyEquals((double)getExpression1().getContent(map, givenCollisionObject), (double)getExpression2().getContent(map, givenCollisionObject)))){
					if((Util.fuzzyLessThanOrEqualTo((double)getExpression1().getContent(map, givenCollisionObject), (double)getExpression2().getContent(map, givenCollisionObject)))){
						return true;
					}
				}
				return false;
			}
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return "";
		}
		catch(NullPointerException exc){
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return "";
		}
	}

}

